﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class JobSection : DmsSectionWithDescription
{
    private DmsProperty? _tempDirectoryProperty;

    internal JobSection(SyntaxToken declareKeywordToken, Identifier identifierName, StringLiteral? description,
        SyntaxNode? parent) :
        base(SyntaxKinds.JobSection, declareKeywordToken, identifierName, description, parent)
    {
    }


    /// <summary>
    ///     [TempDirectory = "Temp Directory"]
    /// </summary>
    public DmsProperty? TempDirectoryProperty => _tempDirectoryProperty;


    public JobSection Update(DmsProperty tempDirectoryProperty)
    {
        SetChildNullableField(ref _tempDirectoryProperty, null, tempDirectoryProperty);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, NameIdentifier, Description, TempDirectoryProperty);
    }
}


public static partial class NodeFactory
{
    public static JobSection CreateJobSection(SyntaxNode? parent, SyntaxToken declareKeywordToken,
        Identifier identifierName, StringLiteral? description, DmsProperty? tempDirectory)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.JobKeywordToken));
        JobSection section = new(declareKeywordToken, identifierName, description, parent);
        if (tempDirectory != null)
        {
            section.Update(tempDirectory);
        }

        return section;
    }
}